/******************************************************************************
秋夜静，独坐对残灯。
啼笑非非谁识我，坐行梦梦尽缘君，何所慰消沉。
风卷雨，雨复卷侬心。
心似欲随风雨去，茫茫大海任浮沉。
无爱亦无恨。
******************************************************************************/
#include "rgb_thread.h"
#include <QDebug>
//#include "LCD/lcd.h"
#include "Curve/hsv.h"
#include "Curve/Curve.h"
#include "Effects/Effects.h"

extern "C" uint32_t tb_get_sys_time_ms(void);
struct mled_pix
{
    union {
        uint32_t pix;
        struct { int16_t y; int16_t x; };
    };
};
struct draw_pixel
{
    union {
        uint32_t pixel;
        struct { int16_t y; int16_t x; };
    };
};
struct matrix_pixel
{
    union
    {
        uint16_t pixel;
        struct
        {
#if 0
            int8_t x;
            int8_t y;
#endif
            uint16_t angle: 9;
            uint16_t radius:7;
        };
    };
};
//#define   MATRIX_SIZE    41
// 旋转模式灯效变换坐标系映射表
/*const uint16_t RotateMatrix[MATRIX_SIZE][MATRIX_SIZE] = {
{0x3887, 0x3885, 0x3683, 0x3482, 0x3480, 0x327E, 0x327C, 0x307B, 0x3078, 0x2E76, 0x2E74, 0x2C72, 0x2C6F, 0x2A6D, 0x2A6A, 0x2A68, 0x2A65, 0x2862, 0x285F, 0x285C, 0x285A, 0x2857, 0x2854, 0x2851, 0x2A4E, 0x2A4B, 0x2A49, 0x2A46, 0x2C44, 0x2C41, 0x2E3F, 0x2E3D, 0x303B, 0x3038, 0x3237, 0x3235, 0x3433, 0x3431, 0x3630, 0x382E, 0x382D, },
{0x3888, 0x3687, 0x3485, 0x3483, 0x3282, 0x3080, 0x307E, 0x2E7C, 0x2E7A, 0x2C78, 0x2C75, 0x2A73, 0x2A70, 0x286E, 0x286B, 0x2868, 0x2865, 0x2662, 0x2660, 0x265D, 0x265A, 0x2656, 0x2653, 0x2651, 0x284E, 0x284B, 0x2848, 0x2845, 0x2A43, 0x2A40, 0x2C3E, 0x2C3B, 0x2E39, 0x2E37, 0x3035, 0x3033, 0x3231, 0x3430, 0x342E, 0x362D, 0x382B, },
{0x368A, 0x3488, 0x3487, 0x3285, 0x3083, 0x3081, 0x2E7F, 0x2C7D, 0x2C7B, 0x2A79, 0x2A77, 0x2874, 0x2871, 0x286F, 0x266C, 0x2669, 0x2666, 0x2463, 0x2460, 0x245D, 0x245A, 0x2456, 0x2453, 0x2450, 0x264D, 0x264A, 0x2647, 0x2844, 0x2842, 0x283F, 0x2A3C, 0x2A3A, 0x2C38, 0x2C36, 0x2E34, 0x3032, 0x3030, 0x322E, 0x342D, 0x342B, 0x3629, },
{0x348B, 0x348A, 0x3288, 0x3087, 0x3085, 0x2E83, 0x2C81, 0x2C7F, 0x2A7D, 0x287A, 0x2878, 0x2675, 0x2673, 0x2670, 0x246D, 0x246A, 0x2467, 0x2264, 0x2260, 0x225D, 0x225A, 0x2256, 0x2253, 0x224F, 0x244C, 0x2449, 0x2446, 0x2643, 0x2640, 0x263E, 0x283B, 0x2839, 0x2A36, 0x2C34, 0x2C32, 0x2E30, 0x302E, 0x302D, 0x322B, 0x3429, 0x3428, },
{0x348D, 0x328B, 0x308A, 0x3088, 0x2E87, 0x2C85, 0x2A83, 0x2A81, 0x287E, 0x287C, 0x267A, 0x2677, 0x2474, 0x2471, 0x226E, 0x226B, 0x2268, 0x2064, 0x2061, 0x205D, 0x205A, 0x2056, 0x2052, 0x204F, 0x224B, 0x2248, 0x2245, 0x2442, 0x243F, 0x263C, 0x2639, 0x2837, 0x2835, 0x2A32, 0x2A30, 0x2C2E, 0x2E2D, 0x302B, 0x3029, 0x3228, 0x3426, },
{0x328F, 0x308D, 0x308C, 0x2E8A, 0x2C88, 0x2A87, 0x2A85, 0x2882, 0x2680, 0x267E, 0x247B, 0x2478, 0x2276, 0x2273, 0x206F, 0x206C, 0x2068, 0x1E65, 0x1E61, 0x1E5D, 0x1E5A, 0x1E56, 0x1E52, 0x1E4E, 0x204B, 0x2047, 0x2044, 0x2240, 0x223D, 0x243B, 0x2438, 0x2635, 0x2633, 0x2831, 0x2A2E, 0x2A2D, 0x2C2B, 0x2E29, 0x3027, 0x3026, 0x3224, },
{0x3291, 0x308F, 0x2E8E, 0x2C8C, 0x2A8A, 0x2A88, 0x2887, 0x2684, 0x2682, 0x2480, 0x227D, 0x227A, 0x2077, 0x2074, 0x1E71, 0x1E6D, 0x1E69, 0x1E66, 0x1C62, 0x1C5E, 0x1C5A, 0x1C55, 0x1C51, 0x1E4D, 0x1E4A, 0x1E46, 0x1E42, 0x203F, 0x203C, 0x2239, 0x2236, 0x2433, 0x2631, 0x262F, 0x282D, 0x2A2B, 0x2A29, 0x2C27, 0x2E25, 0x3024, 0x3222, },
{0x3092, 0x2E91, 0x2C90, 0x2C8E, 0x2A8C, 0x288B, 0x2689, 0x2687, 0x2484, 0x2282, 0x227F, 0x207C, 0x1E79, 0x1E76, 0x1E72, 0x1C6F, 0x1C6B, 0x1C66, 0x1A62, 0x1A5E, 0x1A5A, 0x1A55, 0x1A51, 0x1C4D, 0x1C48, 0x1C44, 0x1E41, 0x1E3D, 0x1E3A, 0x2037, 0x2234, 0x2231, 0x242F, 0x262D, 0x262A, 0x2828, 0x2A27, 0x2C25, 0x2C23, 0x2E22, 0x3021, },
{0x3095, 0x2E93, 0x2C92, 0x2A90, 0x288F, 0x268D, 0x268B, 0x2489, 0x2287, 0x2084, 0x2081, 0x1E7E, 0x1E7B, 0x1C78, 0x1C74, 0x1A70, 0x1A6C, 0x1A68, 0x1863, 0x185E, 0x185A, 0x1855, 0x1850, 0x1A4B, 0x1A47, 0x1A43, 0x1C3F, 0x1C3B, 0x1E38, 0x1E35, 0x2032, 0x202F, 0x222D, 0x242A, 0x2628, 0x2626, 0x2824, 0x2A23, 0x2C21, 0x2E20, 0x301E, },
{0x2E97, 0x2C95, 0x2A94, 0x2893, 0x2891, 0x268F, 0x248D, 0x228B, 0x2089, 0x2087, 0x1E84, 0x1C81, 0x1C7E, 0x1A7A, 0x1A76, 0x1872, 0x186D, 0x1869, 0x1664, 0x165F, 0x165A, 0x1654, 0x164F, 0x184A, 0x1846, 0x1841, 0x1A3D, 0x1A39, 0x1C35, 0x1C32, 0x1E2F, 0x202D, 0x202A, 0x2228, 0x2426, 0x2624, 0x2822, 0x2820, 0x2A1F, 0x2C1E, 0x2E1C, },
{0x2E99, 0x2C98, 0x2A96, 0x2895, 0x2693, 0x2492, 0x2290, 0x228E, 0x208C, 0x1E89, 0x1C87, 0x1C83, 0x1A80, 0x187C, 0x1878, 0x1674, 0x166F, 0x166A, 0x1465, 0x145F, 0x145A, 0x1454, 0x144E, 0x1649, 0x1644, 0x163F, 0x183B, 0x1837, 0x1A33, 0x1C30, 0x1C2D, 0x1E2A, 0x2027, 0x2225, 0x2223, 0x2421, 0x2620, 0x281E, 0x2A1D, 0x2C1B, 0x2E1A, },
{0x2C9B, 0x2A9A, 0x2899, 0x2698, 0x2696, 0x2495, 0x2293, 0x2091, 0x1E8F, 0x1C8C, 0x1C8A, 0x1A87, 0x1883, 0x187F, 0x167B, 0x1477, 0x1471, 0x146C, 0x1266, 0x1260, 0x125A, 0x1253, 0x124D, 0x1447, 0x1442, 0x143C, 0x1638, 0x1834, 0x1830, 0x1A2D, 0x1C29, 0x1C27, 0x1E24, 0x2022, 0x2220, 0x241E, 0x261D, 0x261B, 0x281A, 0x2A19, 0x2C18, },
{0x2C9E, 0x2A9D, 0x289C, 0x269A, 0x2499, 0x2297, 0x2096, 0x1E94, 0x1E92, 0x1C8F, 0x1A8D, 0x188A, 0x1887, 0x1683, 0x147E, 0x147A, 0x1274, 0x126E, 0x1068, 0x1061, 0x105A, 0x1052, 0x104B, 0x1245, 0x123F, 0x1439, 0x1435, 0x1630, 0x182D, 0x1829, 0x1A26, 0x1C24, 0x1E21, 0x1E1F, 0x201D, 0x221C, 0x241A, 0x2619, 0x2817, 0x2A16, 0x2C15, },
{0x2AA0, 0x289F, 0x289E, 0x269D, 0x249C, 0x229A, 0x2099, 0x1E97, 0x1C95, 0x1A93, 0x1891, 0x188E, 0x168A, 0x1487, 0x1282, 0x127D, 0x1077, 0x1071, 0x0E69, 0x0E62, 0x0E5A, 0x0E51, 0x0E4A, 0x1042, 0x103C, 0x1236, 0x1231, 0x142D, 0x1629, 0x1825, 0x1822, 0x1A20, 0x1C1E, 0x1E1C, 0x201A, 0x2219, 0x2417, 0x2616, 0x2815, 0x2814, 0x2A13, },
{0x2AA3, 0x28A2, 0x26A1, 0x24A0, 0x229F, 0x209E, 0x1E9C, 0x1E9B, 0x1C99, 0x1A97, 0x1895, 0x1692, 0x148F, 0x128B, 0x1287, 0x1081, 0x0E7B, 0x0E74, 0x0E6C, 0x0C63, 0x0C5A, 0x0C50, 0x0E47, 0x0E3F, 0x0E38, 0x1032, 0x122D, 0x1228, 0x1424, 0x1621, 0x181E, 0x1A1C, 0x1C1A, 0x1E18, 0x1E17, 0x2015, 0x2214, 0x2413, 0x2612, 0x2811, 0x2A10, },
{0x2AA5, 0x28A5, 0x26A4, 0x24A3, 0x22A2, 0x20A1, 0x1EA0, 0x1C9E, 0x1A9D, 0x189B, 0x1699, 0x1496, 0x1493, 0x1290, 0x108C, 0x0E87, 0x0E80, 0x0C78, 0x0C6F, 0x0A65, 0x0A5A, 0x0A4E, 0x0C44, 0x0C3B, 0x0E33, 0x0E2D, 0x1027, 0x1223, 0x1420, 0x141D, 0x161A, 0x1818, 0x1A16, 0x1C15, 0x1E13, 0x2012, 0x2211, 0x2410, 0x260F, 0x280E, 0x2A0E, },
{0x2AA8, 0x28A8, 0x26A7, 0x24A6, 0x22A5, 0x20A5, 0x1EA4, 0x1CA2, 0x1AA1, 0x18A0, 0x169E, 0x149C, 0x1299, 0x1096, 0x0E92, 0x0E8D, 0x0C87, 0x0A7E, 0x0A74, 0x0868, 0x085A, 0x084B, 0x0A3F, 0x0A35, 0x0C2D, 0x0E26, 0x0E21, 0x101D, 0x121A, 0x1417, 0x1615, 0x1813, 0x1A12, 0x1C11, 0x1E0F, 0x200E, 0x220E, 0x240D, 0x260C, 0x280B, 0x2A0B, },
{0x28AB, 0x26AB, 0x24AA, 0x22A9, 0x20A9, 0x1EA8, 0x1EA7, 0x1CA7, 0x1AA5, 0x18A4, 0x16A3, 0x14A1, 0x129F, 0x109C, 0x0E99, 0x0C95, 0x0A8F, 0x0887, 0x087B, 0x066C, 0x065A, 0x0647, 0x0838, 0x082D, 0x0A24, 0x0C1E, 0x0E1A, 0x1017, 0x1214, 0x1412, 0x1610, 0x180F, 0x1A0E, 0x1C0C, 0x1E0C, 0x1E0B, 0x200A, 0x220A, 0x2409, 0x2608, 0x2808, },
{0x28AE, 0x26AD, 0x24AD, 0x22AD, 0x20AC, 0x1EAC, 0x1CAB, 0x1AAB, 0x18AA, 0x16A9, 0x14A8, 0x12A7, 0x10A5, 0x0EA4, 0x0EA1, 0x0C9E, 0x0A99, 0x0892, 0x0687, 0x0474, 0x045A, 0x043F, 0x062D, 0x0821, 0x0A1A, 0x0C15, 0x0E12, 0x0E0F, 0x100E, 0x120C, 0x140B, 0x160A, 0x1809, 0x1A08, 0x1C08, 0x1E07, 0x2007, 0x2206, 0x2406, 0x2606, 0x2805, },
{0x28B1, 0x26B0, 0x24B0, 0x22B0, 0x20B0, 0x1EB0, 0x1CAF, 0x1AAF, 0x18AF, 0x16AE, 0x14AE, 0x12AD, 0x10AC, 0x0EAB, 0x0CAA, 0x0AA8, 0x08A5, 0x06A1, 0x0499, 0x0487, 0x025A, 0x042D, 0x041A, 0x0612, 0x080E, 0x0A0B, 0x0C09, 0x0E08, 0x1007, 0x1206, 0x1405, 0x1605, 0x1804, 0x1A04, 0x1C04, 0x1E03, 0x2003, 0x2203, 0x2403, 0x2603, 0x2802, },
{0x28B4, 0x26B4, 0x24B4, 0x22B4, 0x20B4, 0x1EB4, 0x1CB4, 0x1AB4, 0x18B4, 0x16B4, 0x14B4, 0x12B4, 0x10B4, 0x0EB4, 0x0CB4, 0x0AB4, 0x08B4, 0x06B4, 0x04B4, 0x02B4, 0x0000, 0x0200, 0x0400, 0x0600, 0x0800, 0x0A00, 0x0C00, 0x0E00, 0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1A00, 0x1C00, 0x1E00, 0x2000, 0x2200, 0x2400, 0x2600, 0x2800, },
{0x28B7, 0x26B8, 0x24B8, 0x22B8, 0x20B8, 0x1EB8, 0x1CB9, 0x1AB9, 0x18B9, 0x16BA, 0x14BA, 0x12BB, 0x10BC, 0x0EBD, 0x0CBE, 0x0AC0, 0x08C3, 0x06C7, 0x04CF, 0x04E1, 0x030E, 0x053B, 0x054E, 0x0756, 0x095A, 0x0B5D, 0x0D5F, 0x0F60, 0x1161, 0x1362, 0x1563, 0x1763, 0x1964, 0x1B64, 0x1D64, 0x1F65, 0x2165, 0x2365, 0x2565, 0x2765, 0x2966, },
{0x28BA, 0x26BB, 0x24BB, 0x22BB, 0x20BC, 0x1EBC, 0x1CBD, 0x1ABD, 0x18BE, 0x16BF, 0x14C0, 0x12C1, 0x10C3, 0x0EC4, 0x0EC7, 0x0CCA, 0x0ACF, 0x08D6, 0x06E1, 0x04F4, 0x050E, 0x0529, 0x073B, 0x0947, 0x0B4E, 0x0D53, 0x0F56, 0x0F59, 0x115A, 0x135C, 0x155D, 0x175E, 0x195F, 0x1B60, 0x1D60, 0x1F61, 0x2161, 0x2362, 0x2562, 0x2762, 0x2963, },
{0x28BD, 0x26BD, 0x24BE, 0x22BF, 0x20BF, 0x1EC0, 0x1EC1, 0x1CC1, 0x1AC3, 0x18C4, 0x16C5, 0x14C7, 0x12C9, 0x10CC, 0x0ECF, 0x0CD3, 0x0AD9, 0x08E1, 0x08ED, 0x06FC, 0x070E, 0x0721, 0x0930, 0x093B, 0x0B44, 0x0D4A, 0x0F4E, 0x1151, 0x1354, 0x1556, 0x1758, 0x1959, 0x1B5A, 0x1D5C, 0x1F5C, 0x1F5D, 0x215E, 0x235E, 0x255F, 0x2760, 0x2960, },
{0x2AC0, 0x28C0, 0x26C1, 0x24C2, 0x22C3, 0x20C3, 0x1EC4, 0x1CC6, 0x1AC7, 0x18C8, 0x16CA, 0x14CC, 0x12CF, 0x10D2, 0x0ED6, 0x0EDB, 0x0CE1, 0x0AEA, 0x0AF4, 0x0900, 0x090E, 0x091D, 0x0B29, 0x0B33, 0x0D3B, 0x0F42, 0x0F47, 0x114B, 0x134E, 0x1551, 0x1753, 0x1955, 0x1B56, 0x1D57, 0x1F59, 0x215A, 0x235A, 0x255B, 0x275C, 0x295D, 0x2B5D, },
{0x2AC3, 0x28C3, 0x26C4, 0x24C5, 0x22C6, 0x20C7, 0x1EC8, 0x1CCA, 0x1ACB, 0x18CD, 0x16CF, 0x14D2, 0x14D5, 0x12D8, 0x10DC, 0x0EE1, 0x0EE8, 0x0CF0, 0x0CF9, 0x0B03, 0x0B0E, 0x0B1A, 0x0D24, 0x0D2D, 0x0F35, 0x0F3B, 0x1141, 0x1345, 0x1548, 0x154B, 0x174E, 0x1950, 0x1B52, 0x1D53, 0x1F55, 0x2156, 0x2357, 0x2558, 0x2759, 0x295A, 0x2B5A, },
{0x2AC5, 0x28C6, 0x26C7, 0x24C8, 0x22C9, 0x20CA, 0x1ECC, 0x1ECD, 0x1CCF, 0x1AD1, 0x18D3, 0x16D6, 0x14D9, 0x12DD, 0x12E1, 0x10E7, 0x0EED, 0x0EF4, 0x0EFC, 0x0D05, 0x0D0E, 0x0D18, 0x0F21, 0x0F29, 0x0F30, 0x1136, 0x133B, 0x1340, 0x1544, 0x1747, 0x194A, 0x1B4C, 0x1D4E, 0x1F50, 0x1F51, 0x2153, 0x2354, 0x2555, 0x2756, 0x2957, 0x2B58, },
{0x2AC8, 0x28C9, 0x28CA, 0x26CB, 0x24CC, 0x22CE, 0x20CF, 0x1ED1, 0x1CD3, 0x1AD5, 0x18D7, 0x18DA, 0x16DE, 0x14E1, 0x12E6, 0x12EB, 0x10F1, 0x10F7, 0x0EFF, 0x0F06, 0x0F0E, 0x0F17, 0x0F1E, 0x1126, 0x112C, 0x1332, 0x1337, 0x153B, 0x173F, 0x1943, 0x1946, 0x1B48, 0x1D4A, 0x1F4C, 0x214E, 0x234F, 0x2551, 0x2752, 0x2953, 0x2954, 0x2B55, },
{0x2CCA, 0x2ACB, 0x28CC, 0x26CE, 0x24CF, 0x22D1, 0x20D2, 0x1ED4, 0x1ED6, 0x1CD9, 0x1ADB, 0x18DE, 0x18E1, 0x16E5, 0x14EA, 0x14EE, 0x12F4, 0x12FA, 0x1100, 0x1107, 0x110E, 0x1116, 0x111D, 0x1323, 0x1329, 0x152F, 0x1533, 0x1738, 0x193B, 0x193F, 0x1B42, 0x1D44, 0x1F47, 0x1F49, 0x214B, 0x234C, 0x254E, 0x274F, 0x2951, 0x2B52, 0x2D53, },
{0x2CCD, 0x2ACE, 0x28CF, 0x26D0, 0x26D2, 0x24D3, 0x22D5, 0x20D7, 0x1ED9, 0x1CDC, 0x1CDE, 0x1AE1, 0x18E5, 0x18E9, 0x16ED, 0x14F1, 0x14F7, 0x14FC, 0x1302, 0x1308, 0x130E, 0x1315, 0x131B, 0x1521, 0x1526, 0x152C, 0x1730, 0x1934, 0x1938, 0x1B3B, 0x1D3F, 0x1D41, 0x1F44, 0x2146, 0x2348, 0x254A, 0x274B, 0x274D, 0x294E, 0x2B4F, 0x2D50, },
{0x2ECF, 0x2CD0, 0x2AD2, 0x28D3, 0x26D5, 0x24D6, 0x22D8, 0x22DA, 0x20DC, 0x1EDF, 0x1CE1, 0x1CE5, 0x1AE8, 0x18EC, 0x18F0, 0x16F4, 0x16F9, 0x16FE, 0x1503, 0x1509, 0x150E, 0x1514, 0x151A, 0x171F, 0x1724, 0x1729, 0x192D, 0x1931, 0x1B35, 0x1D38, 0x1D3B, 0x1F3E, 0x2141, 0x2343, 0x2345, 0x2547, 0x2748, 0x294A, 0x2B4B, 0x2D4D, 0x2F4E, },
{0x2ED1, 0x2CD3, 0x2AD4, 0x28D5, 0x28D7, 0x26D9, 0x24DB, 0x22DD, 0x20DF, 0x20E1, 0x1EE4, 0x1CE7, 0x1CEA, 0x1AEE, 0x1AF2, 0x18F6, 0x18FB, 0x18FF, 0x1704, 0x1709, 0x170E, 0x1714, 0x1719, 0x191E, 0x1922, 0x1927, 0x1B2B, 0x1B2F, 0x1D33, 0x1D36, 0x1F39, 0x213B, 0x213E, 0x2340, 0x2542, 0x2744, 0x2946, 0x2948, 0x2B49, 0x2D4A, 0x2F4C, },
{0x30D3, 0x2ED5, 0x2CD6, 0x2AD8, 0x28D9, 0x26DB, 0x26DD, 0x24DF, 0x22E1, 0x20E4, 0x20E7, 0x1EEA, 0x1EED, 0x1CF0, 0x1CF4, 0x1AF8, 0x1AFC, 0x1B00, 0x1905, 0x190A, 0x190E, 0x1913, 0x1918, 0x1B1D, 0x1B21, 0x1B25, 0x1D29, 0x1D2D, 0x1F30, 0x1F33, 0x2136, 0x2139, 0x233B, 0x253E, 0x2740, 0x2742, 0x2944, 0x2B45, 0x2D47, 0x2F48, 0x314A, },
{0x30D6, 0x2ED7, 0x2CD8, 0x2CDA, 0x2ADC, 0x28DD, 0x26DF, 0x26E1, 0x24E4, 0x22E6, 0x22E9, 0x20EC, 0x1EEF, 0x1EF2, 0x1EF6, 0x1CF9, 0x1CFD, 0x1D02, 0x1B06, 0x1B0A, 0x1B0E, 0x1B13, 0x1B17, 0x1D1B, 0x1D20, 0x1D24, 0x1F27, 0x1F2B, 0x1F2E, 0x2131, 0x2334, 0x2337, 0x2539, 0x273B, 0x273E, 0x2940, 0x2B41, 0x2D43, 0x2D45, 0x2F46, 0x3147, },
{0x32D7, 0x30D9, 0x2EDA, 0x2CDC, 0x2ADE, 0x2AE0, 0x28E1, 0x26E4, 0x26E6, 0x24E8, 0x22EB, 0x22EE, 0x20F1, 0x20F4, 0x1EF7, 0x1EFB, 0x1EFF, 0x1F02, 0x1D06, 0x1D0A, 0x1D0E, 0x1D13, 0x1D17, 0x1F1B, 0x1F1E, 0x1F22, 0x1F26, 0x2129, 0x212C, 0x232F, 0x2332, 0x2535, 0x2737, 0x2739, 0x293B, 0x2B3D, 0x2B3F, 0x2D41, 0x2F43, 0x3144, 0x3346, },
{0x32D9, 0x30DB, 0x30DC, 0x2EDE, 0x2CE0, 0x2AE1, 0x2AE3, 0x28E6, 0x26E8, 0x26EA, 0x24ED, 0x24F0, 0x22F2, 0x22F5, 0x20F9, 0x20FC, 0x2100, 0x1F03, 0x1F07, 0x1F0B, 0x1F0E, 0x1F12, 0x1F16, 0x1F1A, 0x211D, 0x2121, 0x2124, 0x2328, 0x232B, 0x252D, 0x2530, 0x2733, 0x2735, 0x2937, 0x2B3A, 0x2B3B, 0x2D3D, 0x2F3F, 0x3141, 0x3142, 0x3344, },
{0x34DB, 0x32DD, 0x30DE, 0x30E0, 0x2EE1, 0x2CE3, 0x2AE5, 0x2AE7, 0x28EA, 0x28EC, 0x26EE, 0x26F1, 0x24F4, 0x24F7, 0x22FA, 0x22FD, 0x2300, 0x2104, 0x2107, 0x210B, 0x210E, 0x2112, 0x2116, 0x2119, 0x231D, 0x2320, 0x2323, 0x2526, 0x2529, 0x272C, 0x272F, 0x2931, 0x2933, 0x2B36, 0x2B38, 0x2D3A, 0x2F3B, 0x313D, 0x313F, 0x3340, 0x3542, },
{0x34DD, 0x34DE, 0x32E0, 0x30E1, 0x30E3, 0x2EE5, 0x2CE7, 0x2CE9, 0x2AEB, 0x28EE, 0x28F0, 0x26F3, 0x26F5, 0x26F8, 0x24FB, 0x24FE, 0x2501, 0x2304, 0x2308, 0x230B, 0x230E, 0x2312, 0x2315, 0x2319, 0x251C, 0x251F, 0x2522, 0x2725, 0x2728, 0x272A, 0x292D, 0x292F, 0x2B32, 0x2D34, 0x2D36, 0x2F38, 0x313A, 0x313B, 0x333D, 0x353F, 0x3540, },
{0x36DE, 0x34E0, 0x34E1, 0x32E3, 0x30E5, 0x30E7, 0x2EE9, 0x2CEB, 0x2CED, 0x2AEF, 0x2AF1, 0x28F4, 0x28F7, 0x28F9, 0x26FC, 0x26FF, 0x2702, 0x2505, 0x2508, 0x250B, 0x250E, 0x2512, 0x2515, 0x2518, 0x271B, 0x271E, 0x2721, 0x2924, 0x2926, 0x2929, 0x2B2C, 0x2B2E, 0x2D30, 0x2D32, 0x2F34, 0x3136, 0x3138, 0x333A, 0x353B, 0x353D, 0x373F, },
{0x38E0, 0x36E1, 0x34E3, 0x34E5, 0x32E6, 0x30E8, 0x30EA, 0x2EEC, 0x2EEE, 0x2CF0, 0x2CF3, 0x2AF5, 0x2AF8, 0x28FA, 0x28FD, 0x2900, 0x2903, 0x2706, 0x2708, 0x270B, 0x270E, 0x2712, 0x2715, 0x2717, 0x291A, 0x291D, 0x2920, 0x2923, 0x2B25, 0x2B28, 0x2D2A, 0x2D2D, 0x2F2F, 0x2F31, 0x3133, 0x3135, 0x3337, 0x3538, 0x353A, 0x373B, 0x393D, },
{0x38E1, 0x38E3, 0x36E5, 0x34E6, 0x34E8, 0x32EA, 0x32EC, 0x30ED, 0x30F0, 0x2EF2, 0x2EF4, 0x2CF6, 0x2CF9, 0x2AFB, 0x2AFE, 0x2B00, 0x2B03, 0x2906, 0x2909, 0x290C, 0x290E, 0x2911, 0x2914, 0x2917, 0x2B1A, 0x2B1D, 0x2B1F, 0x2B22, 0x2D24, 0x2D27, 0x2F29, 0x2F2B, 0x312D, 0x3130, 0x3331, 0x3333, 0x3535, 0x3537, 0x3738, 0x393A, 0x393B, },
};*/
const uint16_t RotateMatrix[MATRIX_SIZE][MATRIX_SIZE] = {
{0x3A85, 0x3884, 0x3682, 0x3680, 0x347F, 0x327D, 0x327B, 0x3079, 0x3077, 0x2E75, 0x2E73, 0x2C71, 0x2C6E, 0x2C6C, 0x2A69, 0x2A67, 0x2A64, 0x2A62, 0x2A5F, 0x2A5C, 0x2A5A, 0x2A57, 0x2A54, 0x2A51, 0x2A4F, 0x2A4C, 0x2A4A, 0x2C47, 0x2C45, 0x2C42, 0x2E40, 0x2E3E, 0x303C, 0x303A, 0x3238, 0x3236, 0x3434, 0x3633, 0x3631, 0x382F, 0x3A2E, },
{0x3887, 0x3685, 0x3483, 0x3482, 0x3280, 0x327E, 0x307C, 0x2E7B, 0x2E78, 0x2C76, 0x2C74, 0x2A72, 0x2A6F, 0x2A6D, 0x286A, 0x2868, 0x2865, 0x2862, 0x285F, 0x285C, 0x285A, 0x2857, 0x2854, 0x2851, 0x284E, 0x284B, 0x2849, 0x2A46, 0x2A44, 0x2A41, 0x2C3F, 0x2C3D, 0x2E3B, 0x2E38, 0x3037, 0x3235, 0x3233, 0x3431, 0x3430, 0x362E, 0x382D, },
{0x3688, 0x3487, 0x3485, 0x3283, 0x3082, 0x3080, 0x2E7E, 0x2E7C, 0x2C7A, 0x2A78, 0x2A75, 0x2A73, 0x2870, 0x286E, 0x266B, 0x2668, 0x2665, 0x2662, 0x2660, 0x265D, 0x265A, 0x2656, 0x2653, 0x2651, 0x264E, 0x264B, 0x2648, 0x2845, 0x2843, 0x2A40, 0x2A3E, 0x2A3B, 0x2C39, 0x2E37, 0x2E35, 0x3033, 0x3031, 0x3230, 0x342E, 0x342D, 0x362B, },
{0x348A, 0x3488, 0x3287, 0x3085, 0x3083, 0x2E81, 0x2C7F, 0x2C7D, 0x2A7B, 0x2A79, 0x2877, 0x2874, 0x2671, 0x266F, 0x246C, 0x2469, 0x2466, 0x2463, 0x2460, 0x245D, 0x245A, 0x2456, 0x2453, 0x2450, 0x244D, 0x244A, 0x2447, 0x2644, 0x2642, 0x283F, 0x283C, 0x2A3A, 0x2A38, 0x2C36, 0x2C34, 0x2E32, 0x3030, 0x302E, 0x322D, 0x342B, 0x3429, },
{0x348B, 0x328A, 0x3088, 0x3087, 0x2E85, 0x2C83, 0x2C81, 0x2A7F, 0x287D, 0x287A, 0x2678, 0x2675, 0x2473, 0x2470, 0x246D, 0x226A, 0x2267, 0x2264, 0x2260, 0x225D, 0x225A, 0x2256, 0x2253, 0x224F, 0x224C, 0x2249, 0x2446, 0x2443, 0x2440, 0x263E, 0x263B, 0x2839, 0x2836, 0x2A34, 0x2C32, 0x2C30, 0x2E2E, 0x302D, 0x302B, 0x3229, 0x3428, },
{0x328D, 0x308B, 0x308A, 0x2E88, 0x2C87, 0x2A85, 0x2A83, 0x2881, 0x287E, 0x267C, 0x247A, 0x2477, 0x2274, 0x2271, 0x226E, 0x206B, 0x2068, 0x2064, 0x2061, 0x205D, 0x205A, 0x2056, 0x2052, 0x204F, 0x204B, 0x2048, 0x2245, 0x2242, 0x223F, 0x243C, 0x2439, 0x2637, 0x2835, 0x2832, 0x2A30, 0x2A2E, 0x2C2D, 0x2E2B, 0x3029, 0x3028, 0x3226, },
{0x328F, 0x308D, 0x2E8C, 0x2C8A, 0x2A88, 0x2A87, 0x2885, 0x2682, 0x2680, 0x247E, 0x247B, 0x2278, 0x2276, 0x2073, 0x206F, 0x1E6C, 0x1E68, 0x1E65, 0x1E61, 0x1E5D, 0x1E5A, 0x1E56, 0x1E52, 0x1E4E, 0x1E4B, 0x1E47, 0x2044, 0x2040, 0x223D, 0x223B, 0x2438, 0x2435, 0x2633, 0x2631, 0x282E, 0x2A2D, 0x2A2B, 0x2C29, 0x2E27, 0x3026, 0x3224, },
{0x3091, 0x2E8F, 0x2C8E, 0x2C8C, 0x2A8A, 0x2888, 0x2687, 0x2684, 0x2482, 0x2280, 0x227D, 0x207A, 0x2077, 0x1E74, 0x1E71, 0x1C6D, 0x1C69, 0x1C66, 0x1C62, 0x1C5E, 0x1C5A, 0x1C55, 0x1C51, 0x1C4D, 0x1C4A, 0x1C46, 0x1E42, 0x1E3F, 0x203C, 0x2039, 0x2236, 0x2233, 0x2431, 0x262F, 0x262D, 0x282B, 0x2A29, 0x2C27, 0x2C25, 0x2E24, 0x3022, },
{0x2E92, 0x2E91, 0x2C90, 0x2A8E, 0x288C, 0x268B, 0x2689, 0x2487, 0x2284, 0x2282, 0x207F, 0x1E7C, 0x1E79, 0x1C76, 0x1C72, 0x1A6F, 0x1A6B, 0x1A66, 0x1A62, 0x1A5E, 0x1A5A, 0x1A55, 0x1A51, 0x1A4D, 0x1A48, 0x1A44, 0x1C41, 0x1C3D, 0x1E3A, 0x1E37, 0x2034, 0x2231, 0x222F, 0x242D, 0x262A, 0x2628, 0x2827, 0x2A25, 0x2C23, 0x2E22, 0x2E21, },
{0x2E95, 0x2C93, 0x2A92, 0x2890, 0x288F, 0x268D, 0x248B, 0x2289, 0x2087, 0x2084, 0x1E81, 0x1E7E, 0x1C7B, 0x1A78, 0x1A74, 0x1A70, 0x186C, 0x1868, 0x1863, 0x185E, 0x185A, 0x1855, 0x1850, 0x184B, 0x1847, 0x1A43, 0x1A3F, 0x1A3B, 0x1C38, 0x1E35, 0x1E32, 0x202F, 0x202D, 0x222A, 0x2428, 0x2626, 0x2824, 0x2823, 0x2A21, 0x2C20, 0x2E1E, },
{0x2C97, 0x2A95, 0x2A94, 0x2893, 0x2691, 0x248F, 0x228D, 0x228B, 0x2089, 0x1E87, 0x1C84, 0x1C81, 0x1A7E, 0x1A7A, 0x1876, 0x1872, 0x166D, 0x1669, 0x1664, 0x165F, 0x165A, 0x1654, 0x164F, 0x164A, 0x1646, 0x1841, 0x183D, 0x1A39, 0x1A35, 0x1C32, 0x1C2F, 0x1E2D, 0x202A, 0x2228, 0x2226, 0x2424, 0x2622, 0x2820, 0x2A1F, 0x2A1E, 0x2C1C, },
{0x2C99, 0x2A98, 0x2896, 0x2695, 0x2493, 0x2492, 0x2290, 0x208E, 0x1E8C, 0x1C89, 0x1C87, 0x1A83, 0x1880, 0x187C, 0x1678, 0x1674, 0x146F, 0x146A, 0x1465, 0x145F, 0x145A, 0x1454, 0x144E, 0x1449, 0x1444, 0x163F, 0x163B, 0x1837, 0x1833, 0x1A30, 0x1C2D, 0x1C2A, 0x1E27, 0x2025, 0x2223, 0x2421, 0x2420, 0x261E, 0x281D, 0x2A1B, 0x2C1A, },
{0x2A9B, 0x2A9A, 0x2899, 0x2698, 0x2496, 0x2295, 0x2093, 0x1E91, 0x1E8F, 0x1C8C, 0x1A8A, 0x1887, 0x1883, 0x167F, 0x147B, 0x1477, 0x1271, 0x126C, 0x1266, 0x1260, 0x125A, 0x1253, 0x124D, 0x1247, 0x1242, 0x143C, 0x1438, 0x1634, 0x1830, 0x182D, 0x1A29, 0x1C27, 0x1E24, 0x1E22, 0x2020, 0x221E, 0x241D, 0x261B, 0x281A, 0x2A19, 0x2A18, },
{0x2A9E, 0x289D, 0x269C, 0x249A, 0x2299, 0x2297, 0x2096, 0x1E94, 0x1C92, 0x1A8F, 0x188D, 0x188A, 0x1687, 0x1483, 0x147E, 0x127A, 0x1074, 0x106E, 0x1068, 0x1061, 0x105A, 0x1052, 0x104B, 0x1045, 0x103F, 0x1239, 0x1435, 0x1430, 0x162D, 0x1829, 0x1826, 0x1A24, 0x1C21, 0x1E1F, 0x201D, 0x221C, 0x221A, 0x2419, 0x2617, 0x2816, 0x2A15, },
{0x2AA0, 0x289F, 0x269E, 0x249D, 0x229C, 0x209A, 0x1E99, 0x1C97, 0x1A95, 0x1A93, 0x1891, 0x168E, 0x148A, 0x1287, 0x1282, 0x107D, 0x1077, 0x0E71, 0x0E69, 0x0E62, 0x0E5A, 0x0E51, 0x0E4A, 0x0E42, 0x103C, 0x1036, 0x1231, 0x122D, 0x1429, 0x1625, 0x1822, 0x1A20, 0x1A1E, 0x1C1C, 0x1E1A, 0x2019, 0x2217, 0x2416, 0x2615, 0x2814, 0x2A13, },
{0x28A3, 0x26A2, 0x24A1, 0x24A0, 0x229F, 0x209E, 0x1E9C, 0x1C9B, 0x1A99, 0x1897, 0x1695, 0x1492, 0x148F, 0x128B, 0x1087, 0x0E81, 0x0E7B, 0x0C74, 0x0C6C, 0x0C63, 0x0C5A, 0x0C50, 0x0C47, 0x0C3F, 0x0E38, 0x0E32, 0x102D, 0x1228, 0x1424, 0x1421, 0x161E, 0x181C, 0x1A1A, 0x1C18, 0x1E17, 0x2015, 0x2214, 0x2413, 0x2412, 0x2611, 0x2810, },
{0x28A5, 0x26A5, 0x24A4, 0x22A3, 0x20A2, 0x1EA1, 0x1CA0, 0x1A9E, 0x1A9D, 0x189B, 0x1699, 0x1496, 0x1293, 0x1090, 0x0E8C, 0x0E87, 0x0C80, 0x0A78, 0x0A6F, 0x0A65, 0x0A5A, 0x0A4E, 0x0A44, 0x0A3B, 0x0C33, 0x0E2D, 0x0E27, 0x1023, 0x1220, 0x141D, 0x161A, 0x1818, 0x1A16, 0x1A15, 0x1C13, 0x1E12, 0x2011, 0x2210, 0x240F, 0x260E, 0x280E, },
{0x28A8, 0x26A8, 0x24A7, 0x22A6, 0x20A5, 0x1EA5, 0x1CA4, 0x1AA2, 0x18A1, 0x16A0, 0x149E, 0x129C, 0x1099, 0x1096, 0x0E92, 0x0C8D, 0x0A87, 0x0A7E, 0x0874, 0x0868, 0x085A, 0x084B, 0x083F, 0x0A35, 0x0A2D, 0x0C26, 0x0E21, 0x101D, 0x101A, 0x1217, 0x1415, 0x1613, 0x1812, 0x1A11, 0x1C0F, 0x1E0E, 0x200E, 0x220D, 0x240C, 0x260B, 0x280B, },
{0x28AB, 0x26AB, 0x24AA, 0x22A9, 0x20A9, 0x1EA8, 0x1CA7, 0x1AA7, 0x18A5, 0x16A4, 0x14A3, 0x12A1, 0x109F, 0x0E9C, 0x0C99, 0x0A95, 0x0A8F, 0x0887, 0x067B, 0x066C, 0x065A, 0x0647, 0x0638, 0x082D, 0x0A24, 0x0A1E, 0x0C1A, 0x0E17, 0x1014, 0x1212, 0x1410, 0x160F, 0x180E, 0x1A0C, 0x1C0C, 0x1E0B, 0x200A, 0x220A, 0x2409, 0x2608, 0x2808, },
{0x28AE, 0x26AD, 0x24AD, 0x22AD, 0x20AC, 0x1EAC, 0x1CAB, 0x1AAB, 0x18AA, 0x16A9, 0x14A8, 0x12A7, 0x10A5, 0x0EA4, 0x0CA1, 0x0A9E, 0x0899, 0x0692, 0x0487, 0x0474, 0x045A, 0x043F, 0x042D, 0x0621, 0x081A, 0x0A15, 0x0C12, 0x0E0F, 0x100E, 0x120C, 0x140B, 0x160A, 0x1809, 0x1A08, 0x1C08, 0x1E07, 0x2007, 0x2206, 0x2406, 0x2606, 0x2805, },
{0x28B1, 0x26B0, 0x24B0, 0x22B0, 0x20B0, 0x1EB0, 0x1CAF, 0x1AAF, 0x18AF, 0x16AE, 0x14AE, 0x12AD, 0x10AC, 0x0EAB, 0x0CAA, 0x0AA8, 0x08A5, 0x06A1, 0x0499, 0x0287, 0x025A, 0x022D, 0x041A, 0x0612, 0x080E, 0x0A0B, 0x0C09, 0x0E08, 0x1007, 0x1206, 0x1405, 0x1605, 0x1804, 0x1A04, 0x1C04, 0x1E03, 0x2003, 0x2203, 0x2403, 0x2603, 0x2802, },
{0x28B4, 0x26B4, 0x24B4, 0x22B4, 0x20B4, 0x1EB4, 0x1CB4, 0x1AB4, 0x18B4, 0x16B4, 0x14B4, 0x12B4, 0x10B4, 0x0EB4, 0x0CB4, 0x0AB4, 0x08B4, 0x06B4, 0x04B4, 0x02B4, 0x0000, 0x0200, 0x0400, 0x0600, 0x0800, 0x0A00, 0x0C00, 0x0E00, 0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1A00, 0x1C00, 0x1E00, 0x2000, 0x2200, 0x2400, 0x2600, 0x2800, },
{0x28B7, 0x26B8, 0x24B8, 0x22B8, 0x20B8, 0x1EB8, 0x1CB9, 0x1AB9, 0x18B9, 0x16BA, 0x14BA, 0x12BB, 0x10BC, 0x0EBD, 0x0CBE, 0x0AC0, 0x08C3, 0x06C7, 0x04CF, 0x02E1, 0x030E, 0x033B, 0x054E, 0x0756, 0x095A, 0x0B5D, 0x0D5F, 0x0F60, 0x1161, 0x1362, 0x1563, 0x1763, 0x1964, 0x1B64, 0x1D64, 0x1F65, 0x2165, 0x2365, 0x2565, 0x2765, 0x2966, },
{0x28BA, 0x26BB, 0x24BB, 0x22BB, 0x20BC, 0x1EBC, 0x1CBD, 0x1ABD, 0x18BE, 0x16BF, 0x14C0, 0x12C1, 0x10C3, 0x0EC4, 0x0CC7, 0x0ACA, 0x08CF, 0x06D6, 0x04E1, 0x04F4, 0x050E, 0x0529, 0x053B, 0x0747, 0x094E, 0x0B53, 0x0D56, 0x0F59, 0x115A, 0x135C, 0x155D, 0x175E, 0x195F, 0x1B60, 0x1D60, 0x1F61, 0x2161, 0x2362, 0x2562, 0x2762, 0x2963, },
{0x28BD, 0x26BD, 0x24BE, 0x22BF, 0x20BF, 0x1EC0, 0x1CC1, 0x1AC1, 0x18C3, 0x16C4, 0x14C5, 0x12C7, 0x10C9, 0x0ECC, 0x0CCF, 0x0AD3, 0x0AD9, 0x08E1, 0x06ED, 0x06FC, 0x070E, 0x0721, 0x0730, 0x093B, 0x0B44, 0x0B4A, 0x0D4E, 0x0F51, 0x1154, 0x1356, 0x1558, 0x1759, 0x195A, 0x1B5C, 0x1D5C, 0x1F5D, 0x215E, 0x235E, 0x255F, 0x2760, 0x2960, },
{0x28C0, 0x26C0, 0x24C1, 0x22C2, 0x20C3, 0x1EC3, 0x1CC4, 0x1AC6, 0x18C7, 0x16C8, 0x14CA, 0x12CC, 0x10CF, 0x10D2, 0x0ED6, 0x0CDB, 0x0AE1, 0x0AEA, 0x08F4, 0x0900, 0x090E, 0x091D, 0x0929, 0x0B33, 0x0B3B, 0x0D42, 0x0F47, 0x114B, 0x114E, 0x1351, 0x1553, 0x1755, 0x1956, 0x1B57, 0x1D59, 0x1F5A, 0x215A, 0x235B, 0x255C, 0x275D, 0x295D, },
{0x28C3, 0x26C3, 0x24C4, 0x22C5, 0x20C6, 0x1EC7, 0x1CC8, 0x1ACA, 0x1ACB, 0x18CD, 0x16CF, 0x14D2, 0x12D5, 0x10D8, 0x0EDC, 0x0EE1, 0x0CE8, 0x0AF0, 0x0AF9, 0x0B03, 0x0B0E, 0x0B1A, 0x0B24, 0x0B2D, 0x0D35, 0x0F3B, 0x0F41, 0x1145, 0x1348, 0x154B, 0x174E, 0x1950, 0x1B52, 0x1B53, 0x1D55, 0x1F56, 0x2157, 0x2358, 0x2559, 0x275A, 0x295A, },
{0x28C5, 0x26C6, 0x24C7, 0x24C8, 0x22C9, 0x20CA, 0x1ECC, 0x1CCD, 0x1ACF, 0x18D1, 0x16D3, 0x14D6, 0x14D9, 0x12DD, 0x10E1, 0x0EE7, 0x0EED, 0x0CF4, 0x0CFC, 0x0D05, 0x0D0E, 0x0D18, 0x0D21, 0x0D29, 0x0F30, 0x0F36, 0x113B, 0x1340, 0x1544, 0x1547, 0x174A, 0x194C, 0x1B4E, 0x1D50, 0x1F51, 0x2153, 0x2354, 0x2555, 0x2556, 0x2757, 0x2958, },
{0x2AC8, 0x28C9, 0x26CA, 0x24CB, 0x22CC, 0x20CE, 0x1ECF, 0x1CD1, 0x1AD3, 0x1AD5, 0x18D7, 0x16DA, 0x14DE, 0x12E1, 0x12E6, 0x10EB, 0x10F1, 0x0EF7, 0x0EFF, 0x0F06, 0x0F0E, 0x0F17, 0x0F1E, 0x0F26, 0x112C, 0x1132, 0x1337, 0x133B, 0x153F, 0x1743, 0x1946, 0x1B48, 0x1B4A, 0x1D4C, 0x1F4E, 0x214F, 0x2351, 0x2552, 0x2753, 0x2954, 0x2B55, },
{0x2ACA, 0x28CB, 0x26CC, 0x24CE, 0x22CF, 0x22D1, 0x20D2, 0x1ED4, 0x1CD6, 0x1AD9, 0x18DB, 0x18DE, 0x16E1, 0x14E5, 0x14EA, 0x12EE, 0x10F4, 0x10FA, 0x1100, 0x1107, 0x110E, 0x1116, 0x111D, 0x1123, 0x1129, 0x132F, 0x1533, 0x1538, 0x173B, 0x193F, 0x1942, 0x1B44, 0x1D47, 0x1F49, 0x214B, 0x234C, 0x234E, 0x254F, 0x2751, 0x2952, 0x2B53, },
{0x2ACD, 0x2ACE, 0x28CF, 0x26D0, 0x24D2, 0x22D3, 0x20D5, 0x1ED7, 0x1ED9, 0x1CDC, 0x1ADE, 0x18E1, 0x18E5, 0x16E9, 0x14ED, 0x14F1, 0x12F7, 0x12FC, 0x1302, 0x1308, 0x130E, 0x1315, 0x131B, 0x1321, 0x1326, 0x152C, 0x1530, 0x1734, 0x1938, 0x193B, 0x1B3F, 0x1D41, 0x1F44, 0x1F46, 0x2148, 0x234A, 0x254B, 0x274D, 0x294E, 0x2B4F, 0x2B50, },
{0x2CCF, 0x2AD0, 0x28D2, 0x26D3, 0x24D5, 0x24D6, 0x22D8, 0x20DA, 0x1EDC, 0x1CDF, 0x1CE1, 0x1AE5, 0x18E8, 0x18EC, 0x16F0, 0x16F4, 0x14F9, 0x14FE, 0x1503, 0x1509, 0x150E, 0x1514, 0x151A, 0x151F, 0x1524, 0x1729, 0x172D, 0x1931, 0x1935, 0x1B38, 0x1D3B, 0x1D3E, 0x1F41, 0x2143, 0x2345, 0x2547, 0x2548, 0x274A, 0x294B, 0x2B4D, 0x2D4E, },
{0x2CD1, 0x2AD3, 0x2AD4, 0x28D5, 0x26D7, 0x24D9, 0x22DB, 0x22DD, 0x20DF, 0x1EE1, 0x1CE4, 0x1CE7, 0x1AEA, 0x1AEE, 0x18F2, 0x18F6, 0x16FB, 0x16FF, 0x1704, 0x1709, 0x170E, 0x1714, 0x1719, 0x171E, 0x1722, 0x1927, 0x192B, 0x1B2F, 0x1B33, 0x1D36, 0x1D39, 0x1F3B, 0x213E, 0x2340, 0x2342, 0x2544, 0x2746, 0x2948, 0x2B49, 0x2B4A, 0x2D4C, },
{0x2ED3, 0x2CD5, 0x2AD6, 0x28D8, 0x28D9, 0x26DB, 0x24DD, 0x22DF, 0x20E1, 0x20E4, 0x1EE7, 0x1EEA, 0x1CED, 0x1AF0, 0x1AF4, 0x1AF8, 0x18FC, 0x1900, 0x1905, 0x190A, 0x190E, 0x1913, 0x1918, 0x191D, 0x1921, 0x1B25, 0x1B29, 0x1B2D, 0x1D30, 0x1F33, 0x1F36, 0x2139, 0x213B, 0x233E, 0x2540, 0x2742, 0x2944, 0x2945, 0x2B47, 0x2D48, 0x2F4A, },
{0x2ED6, 0x2ED7, 0x2CD8, 0x2ADA, 0x28DC, 0x26DD, 0x26DF, 0x24E1, 0x22E4, 0x22E6, 0x20E9, 0x1EEC, 0x1EEF, 0x1CF2, 0x1CF6, 0x1AF9, 0x1AFD, 0x1B02, 0x1B06, 0x1B0A, 0x1B0E, 0x1B13, 0x1B17, 0x1B1B, 0x1B20, 0x1B24, 0x1D27, 0x1D2B, 0x1F2E, 0x1F31, 0x2134, 0x2337, 0x2339, 0x253B, 0x273E, 0x2740, 0x2941, 0x2B43, 0x2D45, 0x2F46, 0x2F47, },
{0x30D7, 0x2ED9, 0x2CDA, 0x2CDC, 0x2ADE, 0x28E0, 0x26E1, 0x26E4, 0x24E6, 0x22E8, 0x22EB, 0x20EE, 0x20F1, 0x1EF4, 0x1EF7, 0x1CFB, 0x1CFF, 0x1D02, 0x1D06, 0x1D0A, 0x1D0E, 0x1D13, 0x1D17, 0x1D1B, 0x1D1E, 0x1D22, 0x1F26, 0x1F29, 0x212C, 0x212F, 0x2332, 0x2335, 0x2537, 0x2739, 0x273B, 0x293D, 0x2B3F, 0x2D41, 0x2D43, 0x2F44, 0x3146, },
{0x32D9, 0x30DB, 0x2EDC, 0x2CDE, 0x2AE0, 0x2AE1, 0x28E3, 0x26E6, 0x26E8, 0x24EA, 0x24ED, 0x22F0, 0x22F2, 0x20F5, 0x20F9, 0x1EFC, 0x1F00, 0x1F03, 0x1F07, 0x1F0B, 0x1F0E, 0x1F12, 0x1F16, 0x1F1A, 0x1F1D, 0x1F21, 0x2124, 0x2128, 0x232B, 0x232D, 0x2530, 0x2533, 0x2735, 0x2737, 0x293A, 0x2B3B, 0x2B3D, 0x2D3F, 0x2F41, 0x3142, 0x3344, },
{0x32DB, 0x30DD, 0x30DE, 0x2EE0, 0x2CE1, 0x2AE3, 0x2AE5, 0x28E7, 0x28EA, 0x26EC, 0x24EE, 0x24F1, 0x22F4, 0x22F7, 0x22FA, 0x20FD, 0x2100, 0x2104, 0x2107, 0x210B, 0x210E, 0x2112, 0x2116, 0x2119, 0x211D, 0x2120, 0x2323, 0x2326, 0x2329, 0x252C, 0x252F, 0x2731, 0x2933, 0x2936, 0x2B38, 0x2B3A, 0x2D3B, 0x2F3D, 0x313F, 0x3140, 0x3342, },
{0x34DD, 0x32DE, 0x30E0, 0x30E1, 0x2EE3, 0x2CE5, 0x2CE7, 0x2AE9, 0x28EB, 0x28EE, 0x26F0, 0x26F3, 0x24F5, 0x24F8, 0x24FB, 0x22FE, 0x2301, 0x2304, 0x2308, 0x230B, 0x230E, 0x2312, 0x2315, 0x2319, 0x231C, 0x231F, 0x2522, 0x2525, 0x2528, 0x272A, 0x272D, 0x292F, 0x2932, 0x2B34, 0x2D36, 0x2D38, 0x2F3A, 0x313B, 0x313D, 0x333F, 0x3540, },
{0x34DE, 0x34E0, 0x32E1, 0x30E3, 0x30E5, 0x2EE7, 0x2CE9, 0x2CEB, 0x2AED, 0x2AEF, 0x28F1, 0x28F4, 0x26F7, 0x26F9, 0x24FC, 0x24FF, 0x2502, 0x2505, 0x2508, 0x250B, 0x250E, 0x2512, 0x2515, 0x2518, 0x251B, 0x251E, 0x2521, 0x2724, 0x2726, 0x2929, 0x292C, 0x2B2E, 0x2B30, 0x2D32, 0x2D34, 0x2F36, 0x3138, 0x313A, 0x333B, 0x353D, 0x353F, },
{0x36E0, 0x34E1, 0x34E3, 0x32E5, 0x30E6, 0x30E8, 0x2EEA, 0x2EEC, 0x2CEE, 0x2AF0, 0x2AF3, 0x2AF5, 0x28F8, 0x28FA, 0x26FD, 0x2700, 0x2703, 0x2706, 0x2708, 0x270B, 0x270E, 0x2712, 0x2715, 0x2717, 0x271A, 0x271D, 0x2720, 0x2923, 0x2925, 0x2B28, 0x2B2A, 0x2B2D, 0x2D2F, 0x2F31, 0x2F33, 0x3135, 0x3137, 0x3338, 0x353A, 0x353B, 0x373D, },
};

//#define KB_ROW 41
//#define KB_COL 41
void RGB_Thread::AngleRadius(void)
{
    //const struct draw_pixel centre = {.y=(MATRIX_SIZE+1)/2, .x=(MATRIX_SIZE)/2};
    const struct draw_pixel centre = {.y=(MATRIX_SIZE)/2, .x=(MATRIX_SIZE)/2};
    struct matrix_pixel matrix[MATRIX_SIZE][MATRIX_SIZE];
    struct draw_pixel pixel;
    double angle;
    double radius;
    int16_t Angle;
    for(int y=0; y<MATRIX_SIZE; y++)
    {
        for(int x=0; x<MATRIX_SIZE; x++)
        {
            pixel.x = x-centre.x;
            pixel.y = MATRIX_SIZE-y-centre.y;
            angle  = atan2f(pixel.y, pixel.x) * 180 / 3.14159265359;
            radius = sqrt(pow(pixel.x, 2) + pow(pixel.y, 2));//+0.7f;
            Angle = angle;
            if(Angle<0) Angle = 360 + Angle;
            matrix[y][x].angle = Angle;///6;
            matrix[y][x].radius = radius;
        }
    }
    //printf("const uint16_t RotateMatrix[%d][%d] = {\r\n", MATRIX_SIZE, MATRIX_SIZE);
    printf("const uint16_t RotateMatrix[MATRIX_SIZE][MATRIX_SIZE] = {\r\n");
    for(int y=0; y<MATRIX_SIZE; y++)
    {
        printf("{");
        for(int x=0; x<MATRIX_SIZE; x++)
        {
            //printf("%4d, ",  (int)matrix[y][x].angle);
            printf("0x%04X, ",  matrix[y][x].pixel);
        }
        printf("},\r\n");
    }
    printf("};\r\n");
    fflush(stdout);
}

void RGB_Thread::Rotation()  // 旋转效果
{
    // 大坐标系原点
    const int16_t origin_x = 20;
    const int16_t origin_y = 20;
    int index, i;
    struct matrix_pixel kb;
    struct mled_pix pixel;// = {.x=-1, .y=-1,};
    hsv_t hsv;
    uint16_t cnt=Angle;//mled_view.angle;
    //int hue;
    // 设置整体亮度
    uint32_t color;// = mled_rgb_gray(COLOR_RGB_GREEN, mled_grayscale);
    for(index=0; index<KB_ROWS; index++)
    {
        for(i=0; i<KB_COLS; i++)
        {
            pixel.x = i;
            pixel.y = index;
            // 顺时针(CW)
            //if(UP_ROTATE_CW==view_rotate) kb.pixel = RotateMatrix[pixel.y+conv_dy][pixel.x+conv_dx];//kb.pixel = RotateMatrix[pixel.x+conv_dx][pixel.y+conv_dy];
            // ROTATE_CCW,   // 逆时针(CCW)
            //else /*if(ROTATE_CCW==view_rotate)*/ kb.pixel = RotateMatrix[pixel.x+conv_dx][pixel.y+conv_dy];//kb.pixel = RotateMatrix[pixel.y+conv_dy][pixel.x+conv_dx];
//			kb.angle = kb.angle / 15;
//			cIndex = kb.angle*32+cnt+kb.radius*16;
//            cIndex = cIndex%1536;
//			if(cIndex>=1536) cIndex=0;
//			if(cIndex<0) cIndex=1536-1;
//			color = angle_256(cIndex);
            //kb.pixel = RotateMatrix[pixel.y+origin_y][pixel.x+origin_x];
            kb.pixel = RotateMatrix[pixel.y][pixel.x];
#if 1
        hsv.value = 255;
        //hsv.hue = /*abs*/(((kb.angle>>ANGLE_HSV_PRE) - 15 * kb.radius+ (cnt>>1)+360*4) % 360);
        hsv.hue = /*abs*/(((kb.angle>>0) + (cnt>>ANGLE_HSV_PRE)+360*4) % 360);
        //hue = /*abs*/((int)(kb.angle + cnt+360*4) % 360);
        //if(hue<0) hue = -hue;
        //hsv.hue = hue;
        hsv.saturation = 255;
            color = hsv2rgb(&hsv);
#else
            color = angle_hsv_rgb(((kb.angle>>ANGLE_HSV_PRE) - 20 * kb.radius+ (cnt>>1)+360*4) % 360);
#endif
            //qDebug("[%s--%d] bar[%2d]:%08X", __func__, __LINE__, cIndex, color&0x00FFFFFF);
//            color = mled_rgb_gray(color, Grayscale);
//            pixel.pix = mled_kb104_convert_xy(pixel.pix);
//            mled_draw_pixel(pixel.x, pixel.y, color);
            //ugui_pset(pixel.x, pixel.y, color);
            Controller.SetLED(pixel.x, pixel.y, color, 0);
        }
    }
}

void RGB_Thread::SSpiral()    // 螺旋效果
{
    // 大坐标系原点
    const int16_t origin_x = 20;
    const int16_t origin_y = 20;
    int index, i;
    struct matrix_pixel kb;
    struct mled_pix pixel;// = {.x=-1, .y=-1,};
    hsv_t hsv;
    uint16_t cnt=Angle;//mled_view.angle;
    //int hue;
    // 设置整体亮度
    uint32_t color;// = mled_rgb_gray(COLOR_RGB_GREEN, mled_grayscale);
    for(index=0; index<KB_ROWS; index++)
    {
        for(i=0; i<KB_COLS; i++)
        {
            pixel.x = i;
            pixel.y = index;
            // 顺时针(CW)
            //if(UP_ROTATE_CW==view_rotate) kb.pixel = RotateMatrix[pixel.y+conv_dy][pixel.x+conv_dx];//kb.pixel = RotateMatrix[pixel.x+conv_dx][pixel.y+conv_dy];
            // ROTATE_CCW,   // 逆时针(CCW)
            //else /*if(ROTATE_CCW==view_rotate)*/ kb.pixel = RotateMatrix[pixel.x+conv_dx][pixel.y+conv_dy];//kb.pixel = RotateMatrix[pixel.y+conv_dy][pixel.x+conv_dx];
//			kb.angle = kb.angle / 15;
//			cIndex = kb.angle*32+cnt+kb.radius*16;
//            cIndex = cIndex%1536;
//			if(cIndex>=1536) cIndex=0;
//			if(cIndex<0) cIndex=1536-1;
//			color = angle_256(cIndex);
            //kb.pixel = RotateMatrix[pixel.y+origin_y][pixel.x+origin_x];
            kb.pixel = RotateMatrix[pixel.y][pixel.x];
#if 1
        hsv.value = 255;
        //hsv.hue = /*abs*/(((kb.angle>>ANGLE_HSV_PRE) - 15 * kb.radius+ (cnt>>1)+360*4) % 360);
        //hsv.hue = /*abs*/(((kb.angle>>0) - 20 * kb.radius+ (cnt>>ANGLE_HSV_PRE)+360*4) % 360);
        hsv.hue = /*abs*/((kb.angle - 15 * kb.radius + cnt+360*4) % 360);
        //hue = /*abs*/((int)(kb.angle + cnt+360*4) % 360);
        //if(hue<0) hue = -hue;
        //hsv.hue = hue;
        hsv.saturation = 255;
            color = hsv2rgb(&hsv);
#else
            color = angle_hsv_rgb(((kb.angle>>ANGLE_HSV_PRE) - 20 * kb.radius+ (cnt>>1)+360*4) % 360);
#endif
            //qDebug("[%s--%d] bar[%2d]:%08X", __func__, __LINE__, cIndex, color&0x00FFFFFF);
//            color = mled_rgb_gray(color, Grayscale);
//            pixel.pix = mled_kb104_convert_xy(pixel.pix);
//            mled_draw_pixel(pixel.x, pixel.y, color);
            //ugui_pset(pixel.x, pixel.y, color);
            Controller.SetLED(pixel.x, pixel.y, color, 0);
        }
    }
}

void RGB_Thread::WaterWave() // 水波纹效果
{
    // 大坐标系原点
    const int16_t origin_x = 20;
    const int16_t origin_y = 20;
    int index, i;
    struct matrix_pixel kb;
    struct mled_pix pixel;// = {.x=-1, .y=-1,};
    hsv_t hsv;
    uint16_t cnt=Angle;//mled_view.angle;
    //int hue;
    // 设置整体亮度
    uint32_t color;// = mled_rgb_gray(COLOR_RGB_GREEN, mled_grayscale);
    for(index=0; index<KB_ROWS; index++)
    {
        for(i=0; i<KB_COLS; i++)
        {
            pixel.x = i;
            pixel.y = index;
            // 顺时针(CW)
            //if(UP_ROTATE_CW==view_rotate) kb.pixel = RotateMatrix[pixel.y+conv_dy][pixel.x+conv_dx];//kb.pixel = RotateMatrix[pixel.x+conv_dx][pixel.y+conv_dy];
            // ROTATE_CCW,   // 逆时针(CCW)
            //else /*if(ROTATE_CCW==view_rotate)*/ kb.pixel = RotateMatrix[pixel.x+conv_dx][pixel.y+conv_dy];//kb.pixel = RotateMatrix[pixel.y+conv_dy][pixel.x+conv_dx];
            //kb.pixel = RotateMatrix[pixel.y+origin_y][pixel.x+origin_x];
            kb.pixel = RotateMatrix[pixel.y][pixel.x];
            hsv.value = 255;
            hsv.hue = /*abs*/((cnt+360*4-20 * kb.radius) % 360);
            hsv.saturation = 255;
            color = hsv2rgb(&hsv);
            //ugui_pset(pixel.x, pixel.y, color);
            Controller.SetLED(pixel.x, pixel.y, color, 0);
        }
    }
}

void RGB_Thread::loop()
{
    uint32_t cnt=0;
    if(0==isrun())
    {
        QThread::msleep(100);
        return;
    }
    //AngleRadius(MATRIX_SIZE);
    //AngleRadius();
    /*************************************************************************************************\
    |        Advanced [12]                                                                            |
    \*************************************************************************************************/
    //effect = new BouncingBallEffect();      // 弹力球
    //effect = new Bubbles();                 // 气泡
    //effect = new FractalMotion();           // 分形运动
    //effect = new GradientWave();            // 梯度波
    //effect = new MovingPanes();             // 移动窗格
    //effect = new Rain();                    // 下雨
    //effect = new SmoothBlink();             // 平滑闪烁
    //effect = new Spiral();                  // 螺旋
    //effect = new StarryNight();             // 星空
    //effect = new Sunrise();                 // 日出   // Fail
    //effect = new SwirlCircles();            // 漩涡圈
    //effect = new Wavy();                    // 波形的
    //effect = new ZigZag();                  // 之字形的

    /*************************************************************************************************\
    |        Beams [2]                                                                                |
    \*************************************************************************************************/
    //effect = new CrossingBeams();           // 交叉梁
    //effect = new RotatingBeam();            // 旋转射束
    //effect = new RotatingBeamRemodel();     // 旋转射束

    /*************************************************************************************************\
    |        Rainbow [9]                                                                              |
    \*************************************************************************************************/
    //effect = new ColorWheelEffect();        // 色轮
    //effect = new CustomGradientWave();      // 自定义梯度波   // Fail
    //effect = new DoubleRotatingRainbow();   // 双旋转彩虹
    //effect = new Hypnotoad();               // Hypnotoad
    //effect = new NoiseMap();                // 噪声地图
    //effect = new RadialRainbow();           // 径向彩虹
    //effect = new RainbowWave();             // 彩虹波
    //effect = new RotatingRainbow();         // 旋转的彩虹
    //effect = new SpectrumCycling();         // 光谱骑自行车

    /*************************************************************************************************\
    |        Random [2]                                                                               |
    \*************************************************************************************************/
    //effect =  new Bloom();                  // 花朵
    //effect = new Lightning();               // 闪电

    /*************************************************************************************************\
    |        Simple [11]                                                                              |
    \*************************************************************************************************/
    //effect = new Breathing();               // 呼吸
    //effect = new BreathingCircle();         // 呼吸循环
    //effect = new Comet();                   // 彗星
    //effect = new Fill();                    // 充满
    //effect = new Marquee();                 // 大天幕
    //effect = new Mosaic();                  // 马赛克
    //effect = new MotionPoint();             // 运动点
    //effect = new MotionPoints();            // 运动点
    //effect = new Stack();                   // 堆
    //effect = new Swap();                    // 交换
    //effect = new Visor();                   // 遮阳板

    // Test
    effect = new NoiseMap();                // 噪声地图
    effect->OnControllerZonesListChanged(&Controller);
    while(isrun())
    {
        //qDebug("[%s--%d] cnt:%d ", __func__, __LINE__, cnt++);
        //Rotation();
        //SSpiral();
        //WaterWave();
        effect->StepEffect(&Controller);
//        Angle +=6;
//        if(Angle >=360) Angle=0;
        Angle = angle_hsv_up(Angle, 2);//mled_view.angle = angle_1080_down(mled_view.angle, 7);
        if(Angle<2) Angle += 1;
        QThread::msleep(25);
    }
}

